import PopupBase from "../../../components/popups/PopupBase";
import LanguageManager from "../../../core/LanguageManager";
import ResManager from "../../../core/ResManager";
import { ResType } from "../../../net/Commond";
import { BattleTest } from "../../data/BattleTest";
import { ResPath } from "../../data/CFCommon";

const {ccclass, property} = cc._decorator;

@ccclass
export default class PopupCardInfo extends PopupBase<any> {

    @property(cc.Label)
    labHeroName: cc.Label = null;
    @property(cc.Label)
    labRace: cc.Label = null;
    @property(cc.Label)
    labOccupation: cc.Label = null;
    @property(cc.Label)
    labHp: cc.Label = null;
    @property(cc.Label)
    labDef: cc.Label = null;
    @property(cc.Label)
    labAtk: cc.Label = null;
    @property(cc.Label)
    labMagicDef: cc.Label = null;

    @property(cc.Sprite)
    skillIcon: cc.Sprite = null;
    
    @property(cc.Label)
    labSkillName: cc.Label = null;

    @property(cc.RichText)
    labSkillInfo: cc.RichText = null;

    init(heroId:number){
        let heroData = BattleTest.ins().getHeroConfigData(heroId);
        let skillInfo = BattleTest.ins().getSkillData(heroId);
        if(heroData){
            this.labHeroName.string = LanguageManager.ins().getString(heroData.heroName);
            this.labRace.string = LanguageManager.ins().getString("raceName"+heroData.race)
            this.labOccupation.string = LanguageManager.ins().getString("raceName"+heroData.occupation)
            this.labHp.string = heroData.hp;
            this.labDef.string = heroData.def;
            this.labAtk.string = heroData.atk;
            this.labMagicDef.string = heroData.magicDef;
            this.labSkillName.string = LanguageManager.ins().getString(skillInfo.skillName);
            this.labSkillInfo.string = LanguageManager.ins().getString(skillInfo.skillDes);
            ResManager.ins().loadSingle(skillInfo.skillIcon, ResType.image, ResPath.skill_icon, (asset) => {
                this.skillIcon.spriteFrame = asset;
            }, this.node);
        }
    }

    onClose(){
        this.hide();
    }
}
